#include "memory.h"
#include "ui_memory.h"
#include <QMessageBox>
#include <QString>
#include <QFileDialog>
#include <QDebug>
#include <QTextStream>
#include <QFile>
#include <QTextEdit>
#include <QDialog>
#include <QVBoxLayout>
#include "moments.h"
#include "ui_moments.h"

Memory::Memory(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::Memory)
{
    ui->setupUi(this);

    connect(ui->pushButton_3,SIGNAL(triggered(bool)),this,SLOT(on_pushButton_3_clicked(bool)));
}

Memory::~Memory()
{
    delete ui;
}

//关闭界面；
void Memory::on_pushButton_clicked()
{
    this->close();
}


void Memory::on_pushButton_3_clicked(bool checked)
{
    QString fileName = QFileDialog::getOpenFileName(this,
                                                    tr("Open File"), "F:/Qt/", tr("Text (*.txt)"));
    //ui1 = new Ui::Moments;
    ui1->centralwidget->show();
    ui1->textEdit->clear();//刷新文本控件

    file.setFileName(fileName);
    if(!file.open(QIODevice::ReadOnly|QIODevice::Text))
    {
        qDebug()<<checked<<"file open error";
    }

    QTextStream in(&file);
    while (!in.atEnd()) {
        QString str = in.readLine();
        ui1->textEdit->append(str); //追加到控件
    }
}

